package org.authsum.stitches.wicket;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.validation.validator.StringValidator;
import org.authsum.stitches.services.StitchesService;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.springframework.web.context.support.WebApplicationContextUtils; 
import org.codehaus.groovy.grails.web.context.ServletContextHolder; 
import org.springframework.context.ApplicationContext;





public abstract class BasePanel  extends Panel  {
	
	
	protected FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackPanel");

	
	public BasePanel(String id) {
		super(id);

	}
	public StitchesService getStitchesService() {

		//return (StitchesService) grailsApplication.mainContext.getBean("stitchesService");
		ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(ServletContextHolder.getServletContext()); 
		return (StitchesService)ctx.getBean("stitchesService");
      //  return ((WicketApplication)getApplication()).getStitchesService();
		
	}

	
	protected RequiredTextField newRequiredTextField(String id, int maxLength) {
		RequiredTextField textField = new RequiredTextField(id);
		textField.add(StringValidator.maximumLength(maxLength));
		return textField;
	}
	public FeedbackPanel getFeedbackPanel() {
		return feedbackPanel;
	}
	

	private static Log logger = LogFactory.getLog(BasePanel.class);

	
	

	
}
